import request from '@/utils/request'
/**
 * 外呼信息列表
 * @param pageNum
 * @param pageSize
 */
const getList = function(date,pageNum, pageSize) {
  return request({
    url: '/call/getList?date='+date+'&pageNum='+pageNum+"&pageSize="+pageSize,
    method: 'get',
    data: {}
  })
}
/**
 *  加载当前用户指派列表
 * @param pageNum
 * @param pageSize
 */
const getCallUser = function(name) {
  return request({
    url: '/call/getCallUser?name='+name,
    method: 'get',
    data: {}
  })
}
/**
 * 外呼客户信息列表
 * @param pageNum
 * @param pageSize
 */
const getCallList = function(pageNum, pageSize,params) {
  return request({
    url: '/call/getCallList?pageNum='+pageNum+"&pageSize="+pageSize+ '&' +getParam(params),
    method: 'get',
    data: params
  })
}
/**
 * 保存外呼客户
 * @param pageNum
 * @param pageSize
 */
const save = function(params) {
  return request({
    url: '/call/saveCust?'+getParam(params),
    method: 'get',
    data: params
  })
}
/**
 * 更新外呼客户
 * @param pageNum
 * @param pageSize
 */
const update = function(params) {
  return request({
    url: '/call/updateCust?'+getParam(params),
    method: 'get',
    data: params
  })
}
/**
 *  查询历史跟踪客户
 * @param pageNum
 * @param pageSize
 */
const getUnNeeedList = function(pageNum, pageSize,params) {
  return request({
    url: '/call/getUnNeeedList?pageNum='+pageNum+"&pageSize="+pageSize+ '&' +getParam(params),
    method: 'get',
    data: params
  })
}
/**
 * 下载Excel
 * @param url
 * @param data
 */
const expotData = function(url,date) {
  window.location.href = url + '/call/export?date='+date
}
const addDate = function(date, days) {
  if (days == undefined || days == '' ) {
    days = 1
  }
  var date1 = new Date(date)
  date1.setDate(date1.getDate() + Number(days))
  var month = date1.getMonth() + 1
  var day = date1.getDate()
  return date1.getFullYear() + '-' + getFormatDate(month) + '-' + getFormatDate(day)
}
const getFormatDate = function(arg) {
  if (arg == undefined || arg == '') {
    return ''
  }
  var re = arg + ''
  if (re.length < 2) {
    re = '0' + re
  }
  return re
}
/**
 * 参数处理
 * @param params
 */
const getParam = function(params) {
  let ret = ''
  for (const it in params) {
    ret += encodeURIComponent(it) + '=' + encodeURIComponent(params[it]) + '&'
  }
  return ret.substr(0 ,ret.length - 1)
}
Date.prototype.Format = function (fmt) {
  var o = {
    "M+": this.getMonth() + 1,
    "d+": this.getDate(),
    "h+": this.getHours(),
    "m+": this.getMinutes(),
    "s+": this.getSeconds(),
    "q+": Math.floor((this.getMonth() + 3) / 3),
    "S": this.getMilliseconds()
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}
const isNull = function(tmp) {
    if (!tmp || tmp == null || tmp == undefined || tmp == "" || tmp.length == 0 || tmp == "null") {
      tmp = "";
      return tmp;
    } else {
      return tmp;
    }
}
export const callApi = {
  getList: getList,
  getCallList: getCallList,
  getCallUser: getCallUser,
  expotData: expotData,
  addDate:addDate,
  save:save,
  update:update,
  isNull:isNull,
  getUnNeeedList:getUnNeeedList
}
